home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
CLib.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-26
|
2KB
|
153 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "CLib.h"
#include <stdlib.h>
#include <osfcn.h>
#include <unistd.h>
extern int gDebug;
#ifdef __GNUG__
# include <errno.h>
# include <fcntl.h>
#endif
int &CLib::ErrNo= ::errno;
char **CLib::Environ= ::environ;
void CLib::QSort(
void *base, int nel, int width, int (*cmp)(const void*, const void*)
)
{
::qsort(base, nel, width, cmp);
}
char* CLib::BSearch(
const char *key, char *base, unsigned nel, int size,
int (*cmp)(const void*, const void*)
)
{
return (char*) ::bsearch(key, base, nel, size, cmp);
}
char* CLib::Getenv(const char *name)
{
return ::getenv(name);
}
int CLib::Putenv(const char *entry)
{
return ::putenv(entry);
}
int CLib::System(const char *cmd)
{
return ::system(cmd);
}
void CLib::Abort()
{
::abort();
}
unsigned int CLib::Alarm(unsigned int secs)
{
return ::alarm(secs);
}
void CLib::Exit(int code)
{
if (gDebug) {
fprintf(stderr, "Clib::Exit(%d)\n", code);
Abort();
}
return ::exit(code);
}
void CLib::FastExit(int code)
{
return ::_exit(code);
}
int CLib::Open(const char *name, int mode)
{
return ::open(name, mode);
}
int CLib::Creat(const char *name, int mode)
{
return ::creat(name, mode);
}
int CLib::Read(int fd, char *buf, int sz)
{
int ec= ::read(fd, buf, sz);
if (ec < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN)
return -2;
perror("CLib::Read");
return -1; // fatal error
}
return ec; // ok or EOF
}
int CLib::Write(int fd, const char *buf, unsigned int sz)
{
int ec= ::write(fd, buf, sz);
if (ec < 0) {
if (errno == EWOULDBLOCK || errno == EAGAIN)
return -2;
perror("CLib::Write");
return -1; // fatal error
}
return ec;
}
int CLib::Close(int fd)
{
int ec= ::close(fd);
if (ec < 0) {
perror("CLib::Close");
}
return ec;
}
long CLib::Lseek(int fd, long off, int mode)
{
return ::lseek(fd, off, mode);
}
int CLib::Unlink(const char *name)
{
return ::unlink(name);
}
int CLib::Link(const char *from, const char *to)
{
return ::link(from, to);
}
int CLib::Free(char *p)
{
#ifdef __GNUG__
::free(p);
return 0;
#else
return ::free(p);
#endif
}
char *CLib::ReAlloc(char *p, int sz)
{
return ::realloc(p, sz);
}
char *CLib::CAlloc(int n, int sz)
{
return ::calloc(n, sz);
}